import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/store/page/shopping_cart_page.dart';
import 'package:flutter_douban/main_page/store/provider/store_count_model.dart';
import 'package:provider/provider.dart';

class ProductNavView extends StatefulWidget {
  final double? appBarAlpha;
  final double? offset;
  const ProductNavView({Key? key, this.appBarAlpha, this.offset})
      : super(key: key);

  @override
  _ProductNavViewState createState() => _ProductNavViewState();
}

class _ProductNavViewState extends State<ProductNavView> {
  @override
  Widget build(BuildContext context) {
    return Opacity(
        opacity: widget.offset! > 0 ? widget.appBarAlpha! : 1.0,
        child: Stack(
          children: [
            Container(
              height: kToolbarHeight + MediaQuery.of(context).padding.top,
              color: widget.offset! > 0 ? Colors.white : Colors.transparent,
              padding: EdgeInsets.only(left: 20, right: 0, top: 15),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  InkWell(
                    child: Image.asset(
                      'assets/images/common/tab_icon_back.png',
                      width: 22,
                      height: 22,
                      color: widget.offset! > 0 ? Colors.black : Colors.white,
                    ),
                    onTap: () {
                      Navigator.pop(context);
                    },
                  ),
                  _rightWidget(),
                ],
              ),
            ),
            Positioned(
                top: MediaQuery.of(context).padding.top + 8,
                right: 74,
                child: Container(
                  alignment: Alignment.center,
                  width: 16,
                  height: 16,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(8),
                      color: AppColors.danger),
                  child: Text(
                    "${Provider.of<StoreCountModel>(context).count}",
                    style: TextStyle(color: Colors.white, fontSize: 10),
                  ),
                ))
          ],
        ));
  }

  /// 右边分享图片
  Widget _rightWidget() {
    return Row(
      children: [
        IconButton(
            alignment: Alignment.centerRight,
            onPressed: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (_) {
                return ShoppingCartPage();
              }));
            },
            icon: Image(
              image: AssetImage("assets/images/common/navi_item_cart@2x.png"),
              fit: BoxFit.cover,
              width: 24,
              height: 24,
              color: widget.offset! > 0 ? Colors.black : Colors.white,
            )),
        SizedBox(
          width: 15,
        ),
        InkWell(
          child: Image.asset(
            'assets/images/common/share_for_prime@2x.png',
            width: 60,
            height: 50,
          ),
          onTap: () {
            /// 分享赚钱
          },
        ),
      ],
    );
  }
}
